package servlet;

import dao.ProductDAO;
import org.bson.types.ObjectId;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "productDelete",value = "/product/delete")
public class ProductDeleteServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        ObjectId oid=new ObjectId(id);
        ProductDAO productDAO = new ProductDAO();
        int status = productDAO.deleteOne(oid);
        if(status != 0){
            System.out.println("删除成功");
            resp.sendRedirect("/Mall/product/list");
        }
    }
}
